<template>

  <div class="img" :style="note">

    <div style="width: 350px;height: 900px;background-color: rgba(0,0,0,0.01);margin:0px auto;text-align: center;position: relative">
      <div style="width: 350px;height: 500px;background-color: rgba(0,0,0,0.6);text-align: center;position: absolute;margin-top: 100px">
        <p style="font-size: 28px;font-family: '楷体';padding-top: 20px;color: slategray">队伍创建</p>
        <hr style="width: 90%;height: 0.01px"/>
        <div style="margin-top: 20px">
          <div style="width: 100%">
            <form style="width: 100%">
              <p style="width: 100%;text-align: center;color: slategray">请上传队伍头像</p>
              <input type="file" @change="getFile($event)" style="color: slategray">
              <button class="button button-primary button-pill button-small" @click="submit($event)">提交</button>
            </form>
          </div>
          <div style="margin-top: 40px">
            <el-input v-model="InputName" placeholder="请输入团队名称" style="width: 70%"></el-input>
            <!--<el-input v-model="InputNo" placeholder="请输入公司的编号" style="width: 70%;margin-top: 30px"></el-input>-->
            <!--<el-input v-model="CompanyUser" placeholder="请输入该公司的负责人" style="width: 70%;margin-top: 30px"></el-input>-->
            <!--<el-input type="textarea" :rows="2" placeholder="请输入公司情况" v-model="textarea" style="width: 70%;margin-top: 30px" ></el-input>-->
          </div>

          <div style="width: 100%">
            <form style="width: 100%">
              <p style="width: 100%; text-align: center;color: slategray">请将团队人员需求以文档方式上传</p>
              <input type="file" @change="getFilee($event)" style="color: slategray">
              <button class="button button-primary button-pill button-small" @click="submite($event)">提交</button>
            </form>
          </div>

          <div style="width: 100%">
            <el-button plain style="margin-top: 20px;width: 100px" size="small" @click="register()">立即注册</el-button>
          </div>

        </div>

      </div>

    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        note: {
          backgroundImage: "url(" + require("../assets/img/starrr.jpg") + ")",
          backgroundRepeat: "no-repeat",
          backgroundSize: "1890px 1500px",
        },
        pid:'',
        wid:'',
        InputName:'',
        file: '',
        filee: ''
      }
    },
    mounted:function(){

      this.pid = this.$route.query.pid

    },
    methods: {

      getFile: function (evente) {
        this.file = event.target.files[0];
        console.log(this.file);
      },
      getFilee: function (event) {
        this.filee = event.target.files[0];
        console.log(this.filee);
      },
      submit: function (event) {
        //阻止元素发生默认的行为
        var _this=this
        event.preventDefault();
        let formData = new FormData();
        console.log(formData)
        formData.append("file", this.file)
        axios.post('/upload/singlefile', formData)
          .then(function (response) {
            alert(response.data);
            console.log(response);
            var a= response.data;
            // var e=a.split("*");
            //console.log(e[1])
            _this.file=a;
            // window.location.reload();
          })
          .catch(function (error) {
            alert("上传失败");
            console.log(error);
            //window.location.reload();
          });
      },
      submite: function (event) {
        var _this=this
        //阻止元素发生默认的行为
        event.preventDefault();
        let formData = new FormData();
        console.log(formData)
        formData.append("file", this.filee)
        axios.post('/upload/singlefile', formData)
          .then(function (response) {
            alert(response.data);
            console.log(response);
            var a= response.data;
            //  var e=a.split("*");
            //console.log(e[1])
            _this.filee=a;
          })
          .catch(function (error) {
            alert("上传失败");
            console.log(error);
            //window.location.reload();
          });
      },

      register(){

        if(this.InputName=="" ||this.file==''||this.filee=='')
        {
          this.$notify({
            title: '警告',
            message: '请填写注册信息',
            type: 'warning',
            duration:2000
          });
        }else{
          var user= JSON.parse(window.sessionStorage.getItem("user"));
          this.wid=user.id
          axios.post('/workroom/insertTeam',{
            pid:this.pid,
            wid: this.wid,
            tname:this.InputName,
            photo: this.file,
            doc:this.filee

          }).then((response) => {
            if(response.data.states==800){
              this.$notify({
                title: '成功',
                message: '注册成功',
                type: 'success',
                duration:1000
              });
              this.$router.push({
                path: '/Project',
                query: {
                  mallCode: this.pid,
                }
              })


            }else{
              this.$notify.error({
                title: '错误',
                message: response.data.message,
                type: 'warning',
                duration:0
              });
            }
          }).catch((response)=>{

          })
        }

      },


    }



  }
</script>

<style scoped>

</style>
